{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一.模型结构\n",
    "线性回归算是回归任务中比较简单的一种模型，它的模型结构可以表示如下：   \n",
    "\n",
    "$$\n",
    "f(x)=w^Tx^*\n",
    "$$  \n",
    "这里$x^*=[x^T,1]^T$，$x\\in R^n$，所以$w\\in R^{n+1}$，$w$即是模型需要学习的参数，下面造一些伪数据进行演示："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "#造伪样本\n",
    "X=np.linspace(0,100,100)\n",
    "X=np.c_[X,np.ones(100)]\n",
    "w=np.asarray([3,2])\n",
    "Y=X.dot(w)\n",
    "X=X.astype('float')\n",
    "Y=Y.astype('float')\n",
    "X[:,0]+=np.random.normal(size=(X[:,0].shape))*3#添加噪声"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "Y=Y.reshape(100,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0,0.5,'Y')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3X2cjPX+x/HXx1paFUtJLOKUm5JYx+lOnaRTbrqx3YvuO+lGSqRDNz/q1KHITXVyUgkpcSS51w3dOakIySmHIqzbYkkWa/f7+2Nm1+zuNbO7zOzO7Lyfj8c+zFxzXTPfeVw1n+t7fT+f79ecc4iIiBRUoawbICIi0UkBQkREPClAiIiIJwUIERHxpA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A6WXcpiPivx//GvC9c25YwEvTgVv8j28B3ivttoWDc66/c66uc64BvvM13znXDVgAXOPfLWa/H4Bzbguwwcya+DddBPyXcnIO8d1aOtvMqvj/e839fuXmHAYIds6mAzf7s5nOBnbl3oqKVnFZKGdmnfBdgeYua/p0GTfpiJjZecBnwAoO3aN/BN84xGSgPr7/Qa91zhUcUIspZtYWeMg5d5mZ/QFfj6IGsBS40Tm3vyzbdyTMrCW+QfhKwE/Abfgu4srFOTSzJ4Dr8WXdLQX+iu8efMyeQzObCLTFN2vrVmAAMA2Pc+YPjC/iy3raC9zmnFtcFu0urrgMECIiUrR4vMUkIiLFoAAhIiKeFCBERMSTAoSIiHhSgBAREU8KECJh4p9Vd62Z1fA/r+5/flJZt03kcChAiISJc24Dvhk6B/s3DQZGO+d+LrtWiRw+1UGIhJF/ypMlwBjgTiDVP2uwSMypWPQuIlJczrksM+sLzAUuUXCQWKZbTCLh1xHflNanl3VDRI6EAoRIGPnnU7oY38p+D0b7gjAioShAiISJfzK2UfjW41gPDMG3SI5ITFKAEAmfO4H1zrkP/M9fApqa2QVl2CaRw6YsJhER8aQehIiIeFKAEBERTwoQIiLiSQFCREQ8KUCIiIgnBQgREfGkACEiIp4UIERExNP/AwtkW84Wf2liAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2943cc5e7f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "plt.scatter(X[:,0],Y)\n",
    "plt.plot(np.arange(0,100).reshape((100,1)),Y,'r')\n",
    "plt.xlabel('X')\n",
    "plt.ylabel('Y')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二.损失函数\n",
    "利用等式$y=3x+2$我造了一些伪数据，并给$x$添加了一些噪声数据，线性回归的目标即在只有$x,y$的情况下，求解出最优解：$w=[3,2]^T$；可以通过MSE（均方误差）来衡量$f(x)$与$y$的相近程度：  \n",
    "\n",
    "$$\n",
    "L(w)=\\sum_{i=1}^m(y_i-f(x_i))^2=\\sum_{i=1}^m(y_i-w^Tx_i^*)^2=(Y-X^*w)^T(Y-X^*w)\n",
    "$$  \n",
    "\n",
    "这里$m$表示样本量，本例中$m=100$，$x_i,y_i$表示第$i$个样本，$X^*\\in R^{m \\times (n+1)},Y\\in R^{m\\times 1}$，损失函数$L(w)$本质上是关于$w$的函数，通过求解最小的$L(w)$即可得到$w$的最优解：\n",
    "\n",
    "$$\n",
    "w^*=arg \\min_{w}L(w)\n",
    "$$\n",
    "\n",
    "\n",
    "#### 方法一：直接求闭式解\n",
    "\n",
    "而对$\\min L(w)$的求解很明显是一个凸问题（海瑟矩阵${X^*}^TX^*$正定），我们可以直接通过求解$\\frac{dL}{dw}=0$得到$w^*$，梯度推导如下：  \n",
    "\n",
    "$$\n",
    "\\frac{dL}{dw}=-2\\sum_{i=1}^m(y_i-w^Tx_i^*)x_i^*=-2{X^*}^T(Y-X^*w)\\\\\n",
    "$$  \n",
    "令$\\frac{dL}{dw}=0$，可得：$w^*=({X^*}^TX^*)^{-1}{X^*}^TY$，实际情景中数据不一定能满足${X^*}^TX$是满秩（比如$m<n$的情况下，$w$的解有无数种），所以没法直接求逆，我们可以考虑用如下的方式求解：\n",
    "$$\n",
    "{X^*}^+=\\lim_{\\alpha\\rightarrow0}({X^*}^TX^*+\\alpha I)^{-1}{X^*}^T\n",
    "$$  \n",
    "\n",
    "上面的公式即是Moore-Penrose伪逆的定义，但实际求解更多是通过SVD的方式：  \n",
    "\n",
    "$$\n",
    "{X^*}^+=VD^+U^T\n",
    "$$  \n",
    "\n",
    "其中，$U,D,V$是矩阵$X^*$做奇异值分解（SVD）后得到的矩阵，对角矩阵$D$的伪逆$D^+$由其非零元素取倒数之后再转置得到，通过伪逆求解到的结果有如下优点：  \n",
    "\n",
    "（1）当$w$有解时，$w^*={X^*}^+Y$是所有解中欧几里得距离$||w||_2$最小的一个；    \n",
    "\n",
    "（2）当$w$无解时，通过伪逆得到的$w^*$是使得$X^*w^*$与$Y$的欧几里得距离$||X^*w^*-Y||_2$最小  \n",
    "\n",
    "#### 方法二：梯度下降求解\n",
    "\n",
    "但对于数据量很大的情况，求闭式解的方式会让内存很吃力，我们可以通过随机梯度下降法（SGD）对$w$进行更新，首先随机初始化$w$，然后使用如下的迭代公式对$w$进行迭代更新：  \n",
    "$$\n",
    "w:=w-\\eta\\frac{dL}{dw}\n",
    "$$  \n",
    "### 三.模型训练\n",
    "目前我们推导出了$w$的更新公式，接下来编码训练过程："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3.01687627],\n",
       "       [0.0649504 ]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参数初始化\n",
    "w=np.random.random(size=(2,1))\n",
    "#更新参数\n",
    "epoches=100\n",
    "eta=0.0000001\n",
    "losses=[]#记录loss变化\n",
    "for _ in range(epoches):\n",
    "    dw=-2*X.T.dot(Y-X.dot(w))\n",
    "    w=w-eta*dw\n",
    "    losses.append((Y-X.dot(w)).T.dot(Y-X.dot(w)).reshape(-1))\n",
    "w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0,0.5,'Y')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xl8VNX9//HXhxAwuAUVrQRoaGsR0UIQ+dJiXdCKCkrqUmj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3yPWfM5Ron12c0EzvZmMw0ANge7otJVTiyUM7MTCXzzDO5zfVuKq9RsZnY48G/gfer6568hMA4xFehG4H/M051z0YNoGcfMjgKucs4NNbPvEWhR7AVUAGc653aksn7NYWZ9CAzCtwM+Ac4j8OUtaz5HM7sJGE5g9l0FcCGB/veM/hzN7GngKAJZW78AbgTK8PnsvOB4P4FZT9uA85xz5amod6JyIkCIiEjj5UIXk4iINIEChIiI+FKAEBERXwoQIiLiSwFCRER8KUCItBAvw+5KM9vLO+7oHX831XUTaQoFCJEW4pz7jECGzgle0QRginPu09TVSqTptA5CpAV56U8WAg8DFwElXhZhkYzTtuFTRCRRzrlqMxsNvAwcp+AgmUxdTCIt7wQCaa0PTnVFRJpDAUKkBXl5lX5GYJe/K9J9QxiReBQgRFqIl4ztQQJ7c6wGJhHYKEckIylAiLSci4DVzrlXveMHgAPN7MgU1kmkyTSLSUREfKkFISIivhQgRETElwKEiIj4UoAQERFfChAiIuJLAUJERHwpQIiIiC8FCBER8fX/Ad26WbsQ+737AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2944dc82c50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#可视化\n",
    "plt.scatter(X[:,0],Y)\n",
    "plt.plot(X[:,0],X.dot(w),'r')\n",
    "plt.xlabel('X')\n",
    "plt.ylabel('Y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0,0.5,'loss')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAEKCAYAAAC7c+rvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxp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dBzbJNy9e4D1h9y9fCT6JxIHnQmJpJmZHQofbwLOMbPnwzNqEmZ2s5mtDs9kuSbU/2B4TtOPiH4IjJn91MzWhOfaLAtlNxHN7vy8md2T3Fb4JfvN4Rk4L5nZFUn7/mXSc4HuCT88xMxuMrN1oS//mMn/RpK78gevIiIj5HqSzoRCmOx39wVmVgT81sweDXXPAk51941h+bPhl+olwGoz+4m7X29mX3T301O09THgdKLn/kwK2zwV1p0BnEI019dvgfeb2Trgo8DJ7u5mVjniRy+Sgs6EROJzAdH8W88TTXVURfSQMIBnkgII4Mtm9gLwNNHEkfUM7APAve7e7e47gV8BC5L23ezuPcDzQB1wAGgDvm9mHyOaikUk7RRCIvEx4Evufnp4zXL33jOhw8cqRfeSPgQscvf5RHOVFQ9h3/1JnuOsG8gPz8Y5i2hG9MuAR47rSESGSSEkkjkHgXFJyyuBL4THYWBmJ4UHxfU1Hmh19yNmdjLRo9R7dfZu38dTwBXhvlM10VNRn+mvY+GZUOPd/WHgK0SX8kTSTveERDLnRaArXFb7AXAr0aWwZ8PggBZSPyb6EeDzZvYi8CrRJbledwAvmtmz4XESvf4DWAS8QPSwsa+5+44QYqmMAx4ys2Kis6i/GN4hihwfDdEWEZHY6HKciIjERiEkIiKxUQiJiEhsFEIiIhIbhZCIiMRGISQiIrFRCImISGwUQiIiEpv/D5UVP9oGm9FeAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2944dcc1dd8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#loss变化\n",
    "plt.plot(losses)\n",
    "plt.xlabel('iterations')\n",
    "plt.ylabel('loss')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.97642542],\n",
       "       [2.9148446 ]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#当然也可以直接求显式解\n",
    "w=np.linalg.pinv(X).dot(Y)\n",
    "w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0,0.5,'Y')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xt4VOW59/HvTQgatDVYUCGgQUUUtRyk4i6tUmiLB4SIWtRW3VShttoqInKoLVq3AlKhB5UtFregFqWAEaOVWsBaecUaxAMUqBQRCahUwBMBcnjeP2bNZGayZjIhmczp97kurmStWWvyzDU699zP4X7MOYeIiEi0VqlugIiIpCcFCBER8aUAISIivhQgRETElwKEiIj4UoAQERFfChAiIuJLAUJERHwpQIiIiK/WqW5AU7Rv394VFxenuhkiIhll9erV/3HOdWjouowOEMXFxZSXl6e6GSIiGcXM3kvkOnUxiYiILwUIERHxpQAhIiK+FCBERMSXAoSIiPhSgBAREV8KECIi4ksBQkQkk3zxBUyeDNu3J/1PKUCIiGSK3/4WDj8cfvUrePHFpP+5jF5JLSKSE3bsgE6d6o6vuw6uuCLpf1YZhIhIOrv++sjgUFEBs2a1yJ9WgBARSUdr14IZPPBA4Pjee8G5yGCRZOpiEhFJJ7W18O1vw4oVgeO8PNizJzD20MKUQYiIpIsXXggEhGBwWLQIqqtTEhxAGYSISOrt2wfHHQcffRQ4/upXYfVqaJ3aj2hlECIiqTRnDhQU1AWHVavgzTdTHhxAGYSISGp8/DG0b193fNll8Mc/Bgam04QyCBGRljZpUmRw2LwZ5s9Pq+AAChAiIi1n06ZAEJgyJXA8eXJg6mrXrqltVwxJ62Iys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fwXY45yr9o4z/f08HtgJ/J/XjfYHMzuMLHofnXMVwK+BrQQCwyfAarLrfQwX673LuM+iXAgQDe5zncnM7HBgEXCTc+7TVLenOZnZEOAj59zq8NM+l2by+9ka6APMcs71Br4gg7uT/Hh98MOArkAn4DAC3S3RMvl9TETG/bebCwGiwX2uM5WZ5RMIDo875xZ7pz8Mpq3ez49S1b5m0B8YamZbCHQNDiSQURR6XRWQ+e/nNmCbc+5V73ghgYCRTe/jt4F3nXM7nXNVwGLg62TX+xgu1nuXcZ9FuRAgQvtce7MkLgOWpLhNTeb1xc8B1jvnZoQ9tAS42vv9auDplm5bc3HOTXTOdXbOFRN435Y7574PrAAu8S7L9Nf4AfC+mXX3Tg0C/kkWvY8EupbOMrO23n+3wdeYNe9jlFjv3RLgKm8201nAJ8GuqHSVEwvlzOx8At88g/tc35XiJjWZmX0D+DvwNnX985MIjEMsAI4l8D/mpc656EG0jGNmA4BbnHNDzOx4AhnFkcAa4AfOuf2pbF9TmFkvAoPwbYDNwEgCX96y5n00szuAEQRm360BriXQ/57R76OZzQcGEKja+iEwGSjF573zguN9BGY97QVGOufKU9HuROVEgBARkcbLhS4mERE5CAoQIiLiSwFCRER8KUCIiIgvBQgREfGlACHSTLwKu++a2ZHecTvv+LhUt03kYChAiDQT59z7BCp0TvVOTQVmO+feS12rRA6e1kGINCOv/Mlq4GFgFNDbqyIsknFaN3yJiCTKOVdlZuOA54HvKjhIJlMXk0jzO49AWevTUt0QkaZQgBBpRl5dpe8Q2OVvTLpvCCMSjwKESDPxirHNIrA3x1ZgOoGNckQykgKESPMZBWx1zr3gHT8AnGxm56SwTSIHTbOYRETElzIIERHxpQAhIiK+FCBERMSXAoSIiPhSgBAREV8KECIi4ksBQkREfClAiIiIr/8PNgpy8J37/zUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2944dd1d780>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#可视化\n",
    "plt.scatter(X[:,0],Y)\n",
    "plt.plot(X[:,0],X.dot(w),'r')\n",
    "plt.xlabel('X')\n",
    "plt.ylabel('Y')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 四.问题讨论\n",
    "在上面的梯度下降的例子中存在一个问题，$w_1$基本能收敛到3附近，而$w_2$却基本在0附近，很难收敛到2，说明$w_1$比$w_2$更容易收敛($w=[w_1,w_2]^T$)，这很容易理解，模型可以写作：$f(x)=x*w_1+1\\cdot w_2$，如果$x$量纲比1大很多，为了使$f(x)$变化，只需更新少量的$w_1$就能达到目的，而$w_2$的更新动力略显不足；可以考虑用如下方式：  \n",
    "\n",
    "（1）对输入$X$进行归一化，使得$x$无量纲，$w_1,w_2$的更新动力一样（后面封装代码时添加上），如下图；\n",
    "![avatar](./source/01_归一化对梯度下降的影响.png)\n",
    "\n",
    "（2）梯度更新时，$w_1,w_2$使用了一样的学习率，可以让$w_1,w_2$使用不一样的学习率进行更新，比如对$w_2$使用更大的学习率进行更新（可以利用学习率自适应一类的梯度下降法，比如adam），如下图：  \n",
    "![avatar](./source/01_adam.png)\n",
    "### 五.封装与测试\n",
    "接下来简单封装线性回归模型，并放到ml_models.linear_model模块便于后续使用；"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "class LinearRegression(object):\n",
    "    def __init__(self, fit_intercept=True, solver='sgd', if_standard=True, epochs=10, eta=1e-2, batch_size=1):\n",
    "        \"\"\"\n",
    "        :param fit_intercept: 是否训练bias\n",
    "        :param solver:\n",
    "        :param if_standard:\n",
    "        \"\"\"\n",
    "        self.w = None\n",
    "        self.fit_intercept = fit_intercept\n",
    "        self.solver = solver\n",
    "        self.if_standard = if_standard\n",
    "        if if_standard:\n",
    "            self.feature_mean = None\n",
    "            self.feature_std = None\n",
    "        self.epochs = epochs\n",
    "        self.eta = eta\n",
    "        self.batch_size = batch_size\n",
    "\n",
    "    def init_params(self, n_features):\n",
    "        \"\"\"\n",
    "        初始化参数\n",
    "        :return:\n",
    "        \"\"\"\n",
    "        self.w = np.random.random(size=(n_features, 1))\n",
    "\n",
    "    def _fit_closed_form_solution(self, x, y):\n",
    "        \"\"\"\n",
    "        直接求闭式解\n",
    "        :param x:\n",
    "        :param y:\n",
    "        :return:\n",
    "        \"\"\"\n",
    "        self.w = np.linalg.pinv(x).dot(y)\n",
    "\n",
    "    def _fit_sgd(self, x, y):\n",
    "        \"\"\"\n",
    "        随机梯度下降求解\n",
    "        :param x:\n",
    "        :param y:\n",
    "        :param epochs:\n",
    "        :param eta:\n",
    "        :param batch_size:\n",
    "        :return:\n",
    "        \"\"\"\n",
    "        x_y = np.c_[x, y]\n",
    "        # 按batch_size更新w,b\n",
    "        for _ in range(self.epochs):\n",
    "            np.random.shuffle(x_y)\n",
    "            for index in range(x_y.shape[0] // self.batch_size):\n",
    "                batch_x_y = x_y[self.batch_size * index:self.batch_size * (index + 1)]\n",
    "                batch_x = batch_x_y[:, :-1]\n",
    "                batch_y = batch_x_y[:, -1:]\n",
    "\n",
    "                dw = -2 * batch_x.T.dot(batch_y - batch_x.dot(self.w)) / self.batch_size\n",
    "                self.w = self.w - self.eta * dw\n",
    "\n",
    "    def fit(self, x, y):\n",
    "        # 是否归一化feature\n",
    "        if self.if_standard:\n",
    "            self.feature_mean = np.mean(x, axis=0)\n",
    "            self.feature_std = np.std(x, axis=0) + 1e-8\n",
    "            x = (x - self.feature_mean) / self.feature_std\n",
    "        # 是否训练bias\n",
    "        if self.fit_intercept:\n",
    "            x = np.c_[x, np.ones_like(y)]\n",
    "        # 初始化参数\n",
    "        self.init_params(x.shape[1])\n",
    "        # 训练模型\n",
    "        if self.solver == 'closed_form':\n",
    "            self._fit_closed_form_solution(x, y)\n",
    "        elif self.solver == 'sgd':\n",
    "            self._fit_sgd(x, y)\n",
    "\n",
    "    def get_params(self):\n",
    "        \"\"\"\n",
    "        输出原始的系数\n",
    "        :return: w,b\n",
    "        \"\"\"\n",
    "        if self.fit_intercept:\n",
    "            w = self.w[:-1]\n",
    "            b = self.w[-1]\n",
    "        else:\n",
    "            w = self.w\n",
    "            b = 0\n",
    "        if self.if_standard:\n",
    "            w = w / self.feature_std.reshape(-1, 1)\n",
    "            b = b - w.T.dot(self.feature_mean.reshape(-1, 1))\n",
    "        return w.reshape(-1), b\n",
    "\n",
    "    def predict(self, x):\n",
    "        \"\"\"\n",
    "        :param x:ndarray格式数据: m x n\n",
    "        :return: m x 1\n",
    "        \"\"\"\n",
    "        if self.if_standard:\n",
    "            x = (x - self.feature_mean) / self.feature_std\n",
    "        if self.fit_intercept:\n",
    "            x = np.c_[x, np.ones(shape=x.shape[0])]\n",
    "        return x.dot(self.w)\n",
    "\n",
    "    def plot_fit_boundary(self, x, y):\n",
    "        \"\"\"\n",
    "        绘制拟合结果\n",
    "        :param x:\n",
    "        :param y:\n",
    "        :return:\n",
    "        \"\"\"\n",
    "        plt.scatter(x[:, 0], y)\n",
    "        plt.plot(x[:, 0], self.predict(x), 'r')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w (array([2.97494802]), array([[3.14004069]]))\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "9.198087733141367"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#测试\n",
    "lr=LinearRegression(solver='sgd')\n",
    "lr.fit(X[:,:-1],Y)\n",
    "predict=lr.predict(X[:,:-1])\n",
    "#查看w\n",
    "print('w',lr.get_params())\n",
    "#查看标准差\n",
    "np.std(Y-predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF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CvwLuK25rydB7+lHBL72fQis8P6dS2AM+w3gM+9nx+a+1gS939OBIu/3w4B/AmuBvwLtmvv6Gvne+gJLvM+yEDgg3T5H4LfAauAj4FmgXTp8jsDzBO47VBDI2Ef4fXYEhm4e8eLQSgJVSM3+HmL908xYEZE0l0pDNyIi0gAK9CIiaU6BXkQkzSnQi4ikOQV6EZE0p0AvIpLmFOhFRNKcAr2ISJr7f1BhsObUvio4AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2944dd75c18>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#可视化结果\n",
    "lr.plot_fit_boundary(X[:,:-1],Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w (array([2.97642542]), array([[2.9148446]]))\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "9.197986388759377"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#测试\n",
    "lr=LinearRegression(solver='closed_form')\n",
    "lr.fit(X[:,:-1],Y)\n",
    "predict=lr.predict(X[:,:-1])\n",
    "#查看w\n",
    "print('w',lr.get_params())\n",
    "#查看标准差\n",
    "np.std(Y-predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xt4VOW1x/HvIgQNWg0KVQhoUBHFWi6m4imtRWiLWoSIWi+tWm/UVltFRC61RetRQERqq3JE8QheUIoYMbVSC7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9QSSBjvyrWZ0egdPOAF4feITAKqdnfQ7x/mhkrIpLlMql0IyIiDaBALyKS5RToRUSynAK9iEiWU6AXEclyCvQiIllOgV5EJMsp0IuIZLn/B2KwxAohCjP2AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2944de0c780>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#可视化结果\n",
    "lr.plot_fit_boundary(X[:,:-1],Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w: [[2.97642542]] b: [2.9148446]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "9.197986388759379"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#与sklearn对比\n",
    "from sklearn.linear_model import LinearRegression\n",
    "lr=LinearRegression()\n",
    "lr.fit(X[:,:-1],Y)\n",
    "predict=lr.predict(X[:,:-1])\n",
    "#查看w,b\n",
    "print('w:',lr.coef_,'b:',lr.intercept_)\n",
    "#查看标准差\n",
    "np.std(Y-predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
